import configparser
from loguru import logger

logger.add("tool.log", retention="3 days")


class MyConfig:
    def __init__(self):
        self.file = "config.ini"
        logger.info("配置文件加载：{}", self.file)
        self.config = configparser.ConfigParser()
        self.config.read(self.file, encoding="gbk")

    def save(self):
        with open(self.file, "w") as f:
            self.config.write(f)

    def getContent(self, key):
        return self.config.get("content", key)

    def setContent(self, key, val):
        return self.config.set("content", key, val)

    def getVal(self, section, key):
        return self.config.get(section, key)
